{  Statement: http://acmp.ru/?main=task&id_task=39
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i, j, n, cur : longint;
    a, f : array[0..110] of longint;

begin
    reset(input,'input.txt');
    rewrite(output,'output.txt');
    read(n);
    for i := 1 to n do
        read(a[i]);
    f[0] := 0;
    for i := 1 to n do begin
        cur := 0;
        for j := i - 1 downto 0 do
            cur := max(cur, f[j] + a[i] * (i - j));
        f[i] := cur;
    end;
    write(f[n]);
end.